module alady
import StdEnv, japi

/* ********************************
   This example shows how to create 
   and handle mouse events.
   It also shows how to draw images.
******************************** */

:: State = {fr::!F, canvas::!CP, mo::!D}

Start world
# (js, world) = begin_japi world
# title= "Lady in distress"
# (frm, js) = jnewFrame  (WH 580 500) title  js
# (spartan, js)= jloadimage "lambda.jpg" js
# (frm, js) = jseticon frm spartan js 
# (cv, js) = jnewCanvas  (XYWH 0 0 580 500) frm js
# (img,js) = jloadimage "pinup.jpg" js
# cv = jdraw (Img(180, 50) img) cv
# msg= "Click on the yellow pane"
# cv = jdraw (Txt(40, 400) msg) cv
# (cv, js) = jcliprect cv 0 0 300 330 js
# cv = bg_color  yellow cv
# (mp, cv) = jmousepressed cv
# (frm, js) = jshow frm js
# s= {fr= frm, canvas= cv, mo= mp}
# js = loop s js
= end_japi js world
where
  loop :: !State !JS -> *JS
  loop s js
      # (na,js) = jnextaction  js
      | na== (act s.fr)= jquit js
      | na== (act s.mo)
           = loop {s& canvas= here(mxy s.mo) s.canvas} js
      = loop s js
  here ::  (!Int, !Int) !CP -> CP
  here   p=:(x, y) cv
     = draw [ Hue red,
              Rct (x-30, y-20) 70 30,
              Hue blue,
              Cir (x-10, y-5) 5,
              Hue black,
              Txt p "Help!",
              Lin (x,y+20) (x+50,y+30)] cv
    

 